home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicScrollButton.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  160 lines

  1. /*
  2.  * @(#)OrganicScrollButton.java    1.5 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import java.awt.Dimension;
  24. import java.awt.Graphics;
  25. import java.awt.Color;
  26. import java.awt.Polygon;
  27.  
  28. import com.sun.java.swing.*;
  29.  
  30. import com.sun.java.swing.plaf.basic.BasicArrowButton;
  31.  
  32.  
  33. /**
  34.  * JButton object for Organic scrollbar arrows.
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @version 1.5 02/02/98
  44.  * @author Jeff Shapiro
  45.  */
  46. public class OrganicScrollButton extends BasicArrowButton
  47. {
  48.   private static Color buttonColor;
  49.   private static Color buttonHighlightColor;
  50.   private static Color buttonBackgroundColor;
  51.  
  52.   private int buttonWidth;
  53.  
  54.         public OrganicScrollButton( int direction, int width )
  55.         {
  56.             super( direction );
  57.  
  58.         buttonColor = UIManager.getColor("ScrollBar.thumb");
  59.         buttonHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
  60.         buttonBackgroundColor = UIManager.getColor("ScrollBar.background");
  61.  
  62.             buttonWidth = width;
  63.         setRolloverEnabled( true );
  64.         }
  65.  
  66.     public void paint( Graphics g )
  67.         {
  68.         Color origColor;
  69.         boolean isPressed, isRollover, isEnabled;
  70.         int w, h, size;
  71.  
  72.             w = getSize().width;
  73.             h = getSize().height;
  74.         origColor = g.getColor();
  75.         isPressed = getModel().isPressed();
  76.         isRollover = getModel().isRollover();
  77.         isEnabled = isEnabled();
  78.  
  79.             g.setColor( buttonBackgroundColor );
  80.             g.fillRect( 0, 0, w, h );
  81.  
  82.             if ( isPressed || isRollover )
  83.         {
  84.             g.setColor( buttonHighlightColor );
  85.         }
  86.         else  // normal color
  87.         {
  88.                 g.setColor( buttonColor );
  89.             }
  90.  
  91.         Polygon p = new Polygon();
  92.  
  93.         if ( getDirection() == NORTH )
  94.         {
  95.             p.addPoint( 1, h - 1 );
  96.             p.addPoint( 1, 4 );
  97.             p.addPoint( (w) / 2, 1 );
  98.             p.addPoint( (w + 1) / 2, 0 );
  99.             p.addPoint( w, 4 );
  100.             p.addPoint( w, h - 1 );
  101.         }
  102.         else if ( getDirection() == SOUTH )
  103.         {
  104.             p.addPoint( 1, 1 );
  105.             p.addPoint( 1, h - 5 );
  106.             p.addPoint( (w) / 2, h - 1 );
  107.             p.addPoint( (w + 1) / 2, h - 1 );
  108.             p.addPoint( w, h - 5 );
  109.             p.addPoint( w, 1 );
  110.         }
  111.         else if ( getDirection() == EAST )
  112.         {
  113.             p.addPoint( 1, 1 );
  114.             p.addPoint( w - 4, 1 );
  115.             p.addPoint( w - 1, (h) / 2 );
  116.             p.addPoint( w - 1, (h + 1) / 2 );
  117.             p.addPoint( w - 5, h );
  118.             p.addPoint( 1, h );
  119.         }
  120.         else if ( getDirection() == WEST )
  121.         {
  122.             p.addPoint( 1, (h + 1) / 2 );
  123.             p.addPoint( 1, (h) / 2 );
  124.             p.addPoint( 4, 0 );
  125.             p.addPoint( w - 1, 1 );
  126.         p.addPoint( w - 1, h );
  127.             p.addPoint( 4, h );
  128.         }
  129.  
  130.         g.fillPolygon( p );
  131.  
  132.         g.setColor( origColor );
  133.  
  134.         }
  135.  
  136.         public Dimension getPreferredSize()
  137.         {
  138.         if ( direction == NORTH || direction == SOUTH )
  139.         {
  140.             return new Dimension( buttonWidth, 16 );
  141.         }
  142.         else  // EAST or WEST
  143.         {
  144.             return new Dimension( 16, buttonWidth );
  145.         }
  146.         }
  147.  
  148.         public Dimension getMinimumSize()
  149.         {
  150.             return getPreferredSize();
  151.         }
  152.  
  153.         public Dimension getMaximumSize()
  154.         {
  155.             return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
  156.         }
  157.     
  158. }
  159.  
  160.